<template>
  <table>
    <tr>
      <td>书名</td>
      <td>介绍</td>
      <td>价格</td>
      <td>操作</td>
    </tr>
    <tr v-for="(item, index) in resources_list" :key="index">
      <td>{{ item.name }}</td>
      <td>{{ item.depict }}</td>
      <td>￥{{ item.price }}</td>
      <td>
        <van-button
            type="default"
            @click="add_collect(item.id)"
            >收藏</van-button
          >
      </td>
    </tr>
  </table>
</template>

<script>
export default {
  data() {
    return {
      resources_list: "",
      user_id:localStorage.getItem('id')
    };
  },
  mounted() {
    this.resources_show();
  },
  methods: {
    resources_show: function () {
      this.myaxios(this.host + "study/resources/", "get").then((data) => {
        if (data.code == 200) {
          this.$toast.success(data.msg);
          this.resources_list = data.data;
        } else {
          this.$toast.fail(data.msg);
        }
      });
    },
    add_collect: function(id){
      this.myaxios(this.host + "study/collect/" + id + '/', "post",{
        user_id:this.user_id
      }).then((data) => {
        if (data.code == 200) {
          this.$toast.success(data.msg);
        } else {
          this.$toast.fail(data.msg);
        }
      });
    }
  },
};
</script>

<style>
</style>